import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:何人亮
 * Date:2024-08-03
 * 15:10
 */
public class Test {
    public static void main(String[] args) {

    }
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack1=new Stack<>();
        for (String token:tokens) {//遍历String[]
            if(!operation(token)){//判断是不是操作符
                int val=Integer.parseInt(token);//字符串转int
                stack1.push(val );//不是就入栈
            }else{
                int val2=stack1.pop();//栈顶先出在操作符后面；
                int val1=stack1.pop();
                switch (token){
                    case "+":stack1.push(val1+val2);
                        break;
                    case "-":stack1.push(val1-val2);
                        break;
                    case "*":stack1.push(val1*val2);
                        break;
                    case "/":stack1.push(val1/val2);
                        break;
                }
            }
        }
        return stack1.peek();
    }
    public boolean operation(String s){
        if(s.equals("+")||s.equals("-")||s.equals("/")||s.equals("*")){
            return true;
        }
        return false;
    }
}
